package nl.saxion.saktiehuis.dao;

import java.util.List;

import nl.saxion.saktiehuis.model.Order;
import nl.saxion.saktiehuis.util.AbstractDaoImpl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class OrderDaoImpl extends AbstractDaoImpl<Order> implements OrderDao {

	@Override
	public List<Order> getOrdersVoorKlant(String klantNaam) {
		Criteria criteria = getSession().createCriteria(Order.class);
		criteria.createAlias("Klant", "klant");
		criteria.add(Restrictions.eq("klant.naam", klantNaam));
		return criteria.list();
	}

	@Override
	public Order getOrderById(int id) {
		Criteria criteria = getSession().createCriteria(Order.class);
		criteria.add(Restrictions.eq("id", id));
		return (Order) criteria.uniqueResult();
	}
}
